package main

import (
	"cross-server/server"
	"fmt"
	"log"
	"net"
	pb "proto"

	"google.golang.org/grpc"
)

func main() {
	// 启动gRPC服务器
	lis, err := net.Listen("tcp", ":50051") // 使用50051作为默认的gRPC端口
	if err != nil {
		log.Fatalf("Failed to listen: %v", err)
	}

	// 连接到battle-server
	battleConn, err := grpc.Dial("localhost:50052", grpc.WithInsecure())
	if err != nil {
		log.Fatalf("Failed to connect to battle server: %v", err)
	}
	defer battleConn.Close()

	battleClient := pb.NewBattleServiceClient(battleConn)

	s := grpc.NewServer()
	crossServer := server.NewCrossServer(battleClient)
	pb.RegisterCrossServiceServer(s, crossServer)

	fmt.Println("Cross server starting on :50051")
	if err := s.Serve(lis); err != nil {
		log.Fatalf("Failed to serve: %v", err)
	}
}
